package freedoms.yousister.service;

import java.io.IOException;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import freedoms.yousister.R;

public class RingBroadcastReceiver extends BroadcastReceiver {
	
	public static final String RINGBROADCAST="freedoms.yousister.ring";

	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent.getAction().equals(RINGBROADCAST)) {
			System.out.println("广播接收");
			playMp3(context);
		}
	}

	private void playMp3(Context context) {
		MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.ring);
		try {
			mediaPlayer.prepare();
			mediaPlayer.start();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
